package com.ccys.cms.controller.formulation;


import com.ccys.cms.service.formulation.QuantityTypeService;
import com.ccys.common.vo.ResponseResult;
import com.ccys.db.dto.web.formulation.QuantityTypeDto;
import com.ccys.db.dto.web.productAndService.NumEnum;
import com.ccys.db.entity.TblFormulationQuantityType;
import com.ccys.db.mapper.TblFormulationQuantityTypeMapper;
import com.ccys.db.vo.web.formulation.QuantityTypeVo;
import com.ccys.db.vo.web.formulation.UomVo;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@Slf4j
@RestController
@RequestMapping("/formulation")
@Api(tags = "quantityType管理")
public class QuantityTypeController {

    @Resource
    private QuantityTypeService quantityTypeService;


    @Resource
    private TblFormulationQuantityTypeMapper mapper;


    @PostMapping("quantityType")
    @ApiOperation("新增")
    @Transactional
    public ResponseResult insert(TblFormulationQuantityType model) {
        return quantityTypeService.change(model);
    }


    @PutMapping("quantityType")
    @ApiOperation("修改")
    @Transactional
    public ResponseResult update(TblFormulationQuantityType model) {
        return quantityTypeService.change(model);
    }




    @DeleteMapping("quantityType")
    @ApiOperation("根据id删除")
    public ResponseResult delete(String id) {

        TblFormulationQuantityType model = new TblFormulationQuantityType();

        model.setId(id);

        model.setDelFlag(NumEnum.DEL.getCode());

        int i = quantityTypeService.updateEntityById(model);

        return ResponseResult.update(i);

    }


    @GetMapping("quantityType")
    @ApiOperation(value = "查询分页", notes = "排序字段 t5.name(quantityName)/ t4.name (routeDoctorName) / t3.name(routePatientName)  / t1.disp_order / t1.status / t2.user_fullname / t1.created_on")
    public ResponseResult<PageInfo<QuantityTypeVo>, Object> getPage(QuantityTypeDto dto) {

        return quantityTypeService.getPage(dto);
    }


    @GetMapping("quantityType/list")
    @ApiOperation("根据formulationId、routeDoctorId以及routePatientId查询UOM集合")
    public ResponseResult<TblFormulationQuantityType, Object> getList(String formulationId, String routeDoctorId, String routePatientId) {
        List<UomVo> list = mapper.getListByThreeIds(formulationId, routeDoctorId, routePatientId);
        return ResponseResult.success(list);
    }


}
